import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:moose_app/core/model/chat_message_model.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/chat/message_content/text_message.dart';

import 'chat_avatar.dart';

class ATHChatMessageReceiver extends StatelessWidget {
  final ATHChatMessageModel messageModel;

  final GestureTapCallback imageMessageTap;

  ATHChatMessageReceiver({@required this.messageModel, this.imageMessageTap});

  @override
  Widget build(BuildContext context) {
    return _buildReceiveItem();
  }

  Widget _buildReceiveItem() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ATHChatAvatar(
          avatarName: messageModel.userName,
        ),
        Flexible(
          child: Container(
              margin: EdgeInsets.only(left: kSize10), child: _buildContent()),
        )
      ],
    );
  }

  Widget _buildContent() {
    switch (messageModel.messageType) {
      case ATHChatMessageType.text:
        return ATHTextMessage(
          content: messageModel.message,
        );
      case ATHChatMessageType.image:
        return GestureDetector(
          child: Hero(
            tag: "tag1",
            child: messageModel.imageUrl.startsWith("http")
                ? CachedNetworkImage(
                    imageUrl: messageModel.imageUrl,
                    width: kSize200,
                    fit: BoxFit.fill,
                  )
                : Image.asset(
                    messageModel.imageUrl,
                    width: kSize200,
                    fit: BoxFit.fill,
                  ),
          ),
          onTap: imageMessageTap,
        );
        break;
      default:
        return Container(
            width: kSize80, height: kSize80, color: kColorPrimaryLight);
        break;
    }
  }
}
